// ActionScript file
package vivek.project.pocketmoney.investments.model
{
	import flash.events.Event;

	import vivek.project.pocketmoney.admin.model.AdminDataModel;
	import vivek.project.pocketmoney.mutualfund.events.MutualFundEvents;
	import vivek.project.pocketmoney.mutualfund.model.MutualFundDataCache;
	import vivek.project.pocketmoney.mutualfund.model.MutualFundModel;
	import vivek.project.pocketmoney.stocks.StocksEvents;
	import vivek.project.pocketmoney.stocks.model.StockDataCache;
	import vivek.project.pocketmoney.stocks.model.StockDataModel;

	public class InvestmentModel
	{
		private static var instance:InvestmentModel;
		private var mfmodel:MutualFundModel=MutualFundModel.getInstance();
		private var stockModel:StockDataModel=StockDataModel.getInstance();

		public static function getInstance():InvestmentModel
		{
			if (!instance)
			{
				instance=new InvestmentModel();
			}
			return instance;
		}

		public function InvestmentModel():void
		{
			//AdminDataModel.getInstance().addEventListener("USERCHANGED", getAllInvestments);
			mfmodel.addEventListener(MutualFundEvents.MutualFundCachedRefreshed, getAllInvestments);
			stockModel.addEventListener(StocksEvents.StockDataCacheUpdated, getAllInvestments);
			getAllInvestments(null);
		}

		private function getAllInvestments(event:Event):void
		{
			InvestmentDataCache.investmentSummary.source=new Array();
			InvestmentDataCache.investmentSummary.addItem({type: "Mutual Fund", value: MutualFundDataCache.currentHoldingValue});
			InvestmentDataCache.investmentSummary.addItem({type: "Stocks", value: StockDataCache.currentHoldingValue});
			FixedIncomeDataModel.getInstance();
			for each (var obj:Object in InvestmentDataCache.fixedIncomeSummary)
			{
				InvestmentDataCache.investmentSummary.addItem({type: FixedIncomeDataModel.getInstance().getInvestmentTypeName(obj.fm_type), value: obj.fm_investmentamount});
			}
		}
	}
}